package com.ido.babyshow.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.ido.babyshow.model.Photo;
import com.ido.babyshow.util.JsonUtil;
import com.opensymphony.xwork2.ActionSupport;


/**
 * Servlet implementation class ShowPicAction
 */
public class ShowPicAction extends ActionSupport {
	

    public void showPic(){
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response=ServletActionContext.getResponse();
        response.setContentType("application/json;charset=UTF-8");
        List picList=new ArrayList(5);
        Random r=new Random();
      for(int i=0;i<5;i++){        
         int picNum= r.nextInt(5)+1;
          Photo photo=new Photo();
          photo.setId(picNum);
          photo.setLink("#");
          photo.setTitle("瀑布流美女");
          photo.setImageURL("/BabyShow/resource/images/0"+picNum+".jpg");
          picList.add(photo);
      }
        try
        {
            JsonUtil.writeJson(response.getWriter(), picList);
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    
    public String forwardToFlow(){
        return SUCCESS;
}
    
    public void addComments(){
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response=ServletActionContext.getResponse();
        response.setContentType("application/json;charset=UTF-8");
        String imageId=request.getParameter("imageId");
        String comments=request.getParameter("comments");
        
    }

}
